package cn.sumpu.app.guoguojie.biz.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import cn.sumpu.app.guoguojie.biz.MentionBiz;
import cn.sumpu.app.guoguojie.dao.MentionDao;
import cn.sumpu.app.guoguojie.domain.Doing;
import cn.sumpu.app.guoguojie.domain.Mention;
import cn.sumpu.app.guoguojie.util.PageModel;
import cn.sumpu.app.guoguojie.exception.AppBusinessException;


public class MentionBizImpl implements MentionBiz {
	private MentionDao mentionDao;

	public void setMentionDao(MentionDao mentionDao) {
		this.mentionDao = mentionDao;
	}

	//取得全部的省/直辖市的名称
	@Override
	public void addMention(Mention mention) throws AppBusinessException {
		mentionDao.addMention(mention);
	}

	//查询有多少条提到我家的新记录
	@Override
	public Integer getMentionCount(String doorplate)
			throws AppBusinessException {
		return mentionDao.getMentionCount(doorplate);
	}

	//更改家里的提到我家的信息为已读
	@Override
	public void clearMentionByDoorplate(String doorplate)
			throws AppBusinessException {
		mentionDao.clearMentionByDoorplate(doorplate);
	}

	//根据门牌号取得提到我家的信息
	@Override
	public List<Mention> getMentionByDoorplate(Map<String, Object> map)
			throws AppBusinessException {
		return mentionDao.getMentionByDoorplate(map);
	}

	//根据会员ID取得家的门牌号
	@Override
	public String getDoorplateByMember(String member)
			throws AppBusinessException {
		return mentionDao.getDoorplateByMember(member);
	}

	//根据门牌号取得提到我家的信息(分页方法)
	@Override
	public PageModel getMentionByDoorplate(String doorplate, Integer page)
			throws AppBusinessException {
		int pageSize = 20;
		if(page==null)
			page = 1;
		int startId = (page-1)*pageSize;
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("doorplate", doorplate);
		map.put("pageSize", pageSize);
		map.put("startId", startId);
		List<Mention> list = getMentionByDoorplate(map);
		int count = mentionDao.getMentionCountByDoorplate(doorplate);
		PageModel pm = new PageModel();
		pm.setCurrentPage(page);
		pm.setList(list);
		pm.setPageSize(pageSize);
		pm.setTotalRecord(count);
		pm.setTotalPage((count + pageSize - 1) / pageSize);
		return pm;
	}

	@Override
	public String getDoorplateByTopicId(String topicId)
			throws AppBusinessException {
		return mentionDao.getDoorplateByTopicId(topicId);
	}

	@Override
	public Doing getDoingById(String doingId) throws AppBusinessException {
		return mentionDao.getDoingById(doingId);
	}

	//根据群标题的回复ID删除提到我家的
	@Override
	public void deleteMentionById(String topicReplyId)
			throws AppBusinessException {
		mentionDao.deleteMentionById(topicReplyId);
	}

	//根据群标题的ID删除提到我家的
	@Override
	public void deleteMentionByCrowdTopicId(String replyId)
			throws AppBusinessException {
		mentionDao.deleteMentionByCrowdTopicId(replyId);
	}
	//根据条件批量删除提到我家的
	@Override
	public void deleteMentionByCondition(String id, String type)
			throws AppBusinessException {
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("id", id);
		map.put("type", type);
		mentionDao.deleteMentionByCondition(map);
	}

	//根据条件批量屏蔽提到我家的
	@Override
	public void updateMentionByCondition(Boolean enabled, String idList, String type)
			throws AppBusinessException {
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("enabled", enabled);
		map.put("mentionId", idList);
		map.put("mention_type", type);
		mentionDao.updateMentionByCondition(map);
	}

}
